<template>
	<view v-if="JSON.stringify(entrustObj)!='{}'">
		<cu-custom bgColor="bg-black" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">委托详情</block>
		</cu-custom>
		<view @click="handAgency" v-if="userMsg.identity==2&&entrustObj.isResult==2" class="cu-avatar xl round margin-left bg-yellow my-agency">
			<text class="avatar-text text-white">我要代理</text>
		</view>
		<view class="cu-card dynamic no-card">
			<view class="cu-item shadow">
				<view class="cu-list menu-avatar">
					<view class="cu-item ">
						<view class="cu-avatar round lg" :style="{backgroundImage:'url('+ entrustObj.handlUrl +')'}"></view>
						<view class="content flex-sub">
							<!-- <view>凯尔</view> -->
							<view class="text-grey">
								<view class="item_name">
									{{entrustObj.nickName}}
								</view>
								<!-- entrustObj.isResult==2 -->

							</view>
							<view class="text-gray text-sm flex justify-between">
								{{entrustObj.caseAddress}}
							</view>
						</view>
						<view class="cu-tag light bg-blue">
							{{entrustObj.dataValue}}
						</view>
					</view>
				</view>
				<view class="text-content" style="margin-top: 10upx;">
					{{entrustObj.caseContent}}
				</view>
				<view class="pic_title flex solid-bottom padding justify-start align-center">
					<view class="item_name " style="margin-right: 20upx;">
						委托报价:
					</view>
					<view class="text-price text-red">
						{{entrustObj.entrustPrice}}
					</view>
					<view class="cu-tag bg-red radius" style="color: #fff;margin-left: 30upx;" v-if="entrustObj.isUrgent==1">
						加急
					</view>
					<view v-if="entrustObj.isResult==1" class="cu-tag bg-blue radius" style="color: #fff;">
						案件已受理
					</view>
				</view>
			</view>
		</view>
		<view class="line-row">

		</view>
		<view style="text-align: center;" v-if="entrustObj.yuEntrustList.length==0">
			<image src="../../../static/img-no-data.png" style="width: 320upx;
		height: 320upx;margin: 200upx auto;" mode=""></image>
		</view>
		<view class="cu-list menu-avatar" v-if="entrustObj.yuEntrustList.length!=0">
			<view class="cu-item" v-for="item in entrustObj.yuEntrustList" :key='item.id'>
				<view @click="handNavDetails(item.id)" class="cu-avatar round lg" :style="{backgroundImage:'url('+ item.clientUrl +')'}"></view>
				<view class="content">
					<view class="text-grey">{{item.clientName}}<view class="padding-xs text-lg">
						<view class="cu-tag bg-yellow radius" style="color: #fff;">
							平台认证律师
						</view>
					</view></view>
					
					<view class="text-gray text-sm flex">
						<view class="text-cut">
							<text class="text-red  margin-right-xs"></text>
							{{item.content}}
						</view>
					</view>
				</view>
				<view class="action" style="width: 120upx;">
					<view class="text-grey text-xs">22:20</view>
					<view class="margin-top-sm text-center">
						<button v-if="entrustObj.userId==userMsg.id&&entrustObj.isResult==2" @click="handAssign(item)" class=" cu-btn round line-blue"
						 style="font-size: 20upx; height: 40upx;"> 选择他</button>
					</view>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		compare
	} from '../../../core/utit.js'
	export default {
		data() {
			return {
				isCard: true,
				entrustObj: {},
				replyList: [],
				userMsg: {},
				postid: '',
				newIndex: 3,
				newId: ""
			};
		},
		async onLoad(e) {
			if (uni.getStorageSync('USER')) {
				this.userMsg = JSON.parse(uni.getStorageSync('USER'))
			}
			this.newId = e.id
			console.log(this.userMsg, 'userMsguserMsguserMsg')
			let res = await this.http.getDetailsTow(e.id)
			console.log(res, this.userMsg)
			this.entrustObj = res

		},
		async mounted() {

		},
		methods: {
			handAgency() {
				uni.showModal({
					title: '是否代理该案件',
					success: async (res) => {
						if (res.confirm == true) {

							await this.http.editAgency({
								handleId: this.entrustObj.id,
								userId: this.userMsg.id,
							})
							let data = await this.http.getDetailsTow(this.newId)
							this.entrustObj = data
							uni.showToast({
								title: '代理成功,等待客户确认',
								icon: 'none'
							})
						}

					}
				})

			},
			handAssign(item) {
				console.log(item)
				uni.showModal({
					title: '是否选择该律师',
					success: async (res) => {
						if (res.confirm == true) {
							await this.http.editYuEntrust({
								id: item.id,
								isAgree: 1,
								handleId: item.handleId
							})
							uni.showToast({
								title: '选择成功,正在创建聊天室...',
								icon: 'none'
							})
							await this.http.saveChatRoom({
								lawId: item.userId,
								isOpen: 1
							})
							uni.showToast({
								title: '聊天室创建成功',
								icon: 'none'
							})
							uni.navigateTo({
								url: '/pages/message/myConsult/myConsult'
							})

						}


					}
				})
			},
			handNavDetails(id) {
				uni.navigateTo({
					url: '/pages/message/lawyerDetails/lawyerDetails?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.my-agency {
		position: fixed;
		bottom: 50upx;
		right: 20upx;
		z-index: 9999999;
		animation: myfirst 1.2s infinite;
	}

	page {
		background-color: #fff;
	}

	.pic_title {
		border-top: 0.5px solid #eee;
	}

	.sub_btn_box {
		width: 100%;
		height: 100upx;
		padding: 0 30upx;
		background: rgba(255, 255, 255, 1);
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: fixed;
		bottom: 0;
		box-sizing: border-box;

		.btns {
			display: flex;

		}

		.sub_pic {
			.com_pic {
				color: #323233;
				font-size: 32upx;
				font-weight: bold;
			}

			.vip_pic {
				color: #E02020;
				font-size: 30upx;
				margin-top: 12upx;
			}
		}
	}

	@keyframes myfirst {
		0% {
			transform: translate(0px, 0px);
		}

		50% {
			transform: translate(0px, 10px);
		}

		100% {
			transform: translate(0px, 0px);
		}
	}
</style>
